VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmUserManager 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Users Management"
   ClientHeight    =   4185
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   8070
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   4185
   ScaleWidth      =   8070
   Begin VB.CommandButton Command1 
      Caption         =   "Close"
      Height          =   495
      Left            =   6240
      TabIndex        =   4
      Top             =   2640
      Width           =   1455
   End
   Begin MSComctlLib.ListView lstUser 
      Height          =   3615
      Left            =   120
      TabIndex        =   3
      Top             =   240
      Width           =   5775
      _ExtentX        =   10186
      _ExtentY        =   6376
      View            =   3
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      FullRowSelect   =   -1  'True
      GridLines       =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   3
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Text            =   "User"
         Object.Width           =   2646
      EndProperty
      BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   1
         Text            =   "Name"
         Object.Width           =   3705
      EndProperty
      BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   2
         Text            =   "Permission"
         Object.Width           =   3528
      EndProperty
   End
   Begin VB.CommandButton cmdChange 
      Caption         =   "Change password"
      Height          =   495
      Left            =   6240
      TabIndex        =   2
      Top             =   1680
      Width           =   1455
   End
   Begin VB.CommandButton cmdAdd 
      Caption         =   "Add new user"
      Height          =   495
      Left            =   6240
      TabIndex        =   1
      Top             =   1080
      Width           =   1455
   End
   Begin VB.CommandButton cmdDelete 
      Caption         =   "Delete User"
      Height          =   495
      Left            =   6240
      TabIndex        =   0
      Top             =   480
      Width           =   1455
   End
End
Attribute VB_Name = "frmUserManager"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdAdd_Click()
frmAdd.UserName = ""
    frmAdd.Show
End Sub
Private Sub cmdChange_Click()
If Trim(lstUser.SelectedItem) <> "" Then
    frmChgPass.UserName = lstUser.SelectedItem
    frmChgPass.Show
Else
    MsgBox "You must select an user before click Change Password button"
End If
End Sub
Private Sub cmdDelete_Click()
On Error GoTo L
Dim sql As String
Dim conf As Integer
        If lstUser.ListItems.Count < 1 Then
            Exit Sub
        End If
        If Trim(lstUser.SelectedItem) = "" Then
            MsgBox "You must select an user"
            Exit Sub
        End If
        conf = MsgBox("Do you want to delete this user?(Y/N)", vbQuestion + vbYesNo + vbDefaultButton2, "Delete user")
        If conf = vbNo Then Exit Sub
        sql = "Delete from tbl_pass where username ='" & lstUser.SelectedItem & "'"
        adoConnection.Execute (sql)
        displayUser
        Exit Sub
L:
    MsgBox "Unable to delete this user"
End Sub


Private Sub Command1_Click()
    Unload Me
End Sub

Private Sub Form_Load()
Me.Top = Screen.Height / 2 - (Me.Height / 1.5)
    Me.Left = Screen.Width / 2 - (Me.Width / 2)
 
'Call KetNoi
displayUser
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'Call DisconnectDB
End Sub

Private Sub lstUser_DblClick()

If lstUser.SelectedItem = "" Then
    MsgBox "You must select an user"
Else
    InfoFlag = True
    frmAdd.UserName = lstUser.SelectedItem
    frmAdd.Show
End If

End Sub

'-------------------- USER DEFINE -------------
Public Function displayUser()
        Dim rs As ADODB.Recordset
        Dim sql As String
        Dim item
        Set rs = New ADODB.Recordset
        sql = "Select * from tbl_pass"
        Call KetNoi
        Set rs = adoConnection.Execute(sql)
        lstUser.ListItems.Clear
        Do While rs.EOF = False
            Set item = lstUser.ListItems.Add(, , rs!UserName)
            item.SubItems(1) = rs!Name
            Select Case rs!permit
                Case "U"
                    item.SubItems(2) = "User"
                Case "R"
                    item.SubItems(2) = "Reporter"
                Case "A"
                    item.SubItems(2) = "Admin"
                 Case "B"
                    item.SubItems(2) = "MB"
                 Case "G"
                    item.SubItems(2) = "GM"
            End Select
            rs.MoveNext
        Loop
        rs.Close
        Set rs = Nothing
End Function
